package VacationHomework.LeetCode;


public class Num1816 {
    public String truncateSentence(String s, int k) {
        StringBuilder sb=new StringBuilder();
        int count=0;
       for(char a:s.toCharArray()){
           if(a==' '){
               count++;
           }
           if(count==k){
               return sb.toString();
           }
           sb.append(a);
       }
        return sb.toString();
    }
}
